package mycoffee.order.adapter;

import java.util.List;

import mycoffee.order.R;
import mycoffee.order.model.Constants;
import mycoffee.order.model.Food;
import mycoffee.order.model.Order;
import mycoffee.order.model.OrdersDetail;
import mycoffee.order.model.Table;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

/**
 * 
 * @author Binh
 * 
 */
public class InvoiceAdapter extends BaseAdapter {
	/** Interface to global information about an application environment. */
	protected Context mContext;
	/** used to instantiate layout XML file into its corresponding View objects. */
	private LayoutInflater infalInflater;
	private List<Order> mInvoices;
	private int mCurrentInvoiceSelectedIndex = Constants.INVALID_VALUE;

	public InvoiceAdapter(Context context, List<Order> objects) {
		super();
		this.mInvoices = objects;
		this.mContext = context;
		this.infalInflater = LayoutInflater.from(context);
	}

	@Override
	public int getCount() {
		if (this.mInvoices != null) {
			return this.mInvoices.size();
		}
		
		return 0;
	}

	@Override
	public Object getItem(int position) {
		if (this.mInvoices != null && this.mInvoices.size() > position
				&& position >= 0) {
			return mInvoices.get(position);
		}
		
		return null;
	}

	@Override
	public long getItemId(int position) {

		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		if (convertView == null) {
			convertView = this.infalInflater.inflate(R.layout.invoice_item, null);
		}

		if ( position == mCurrentInvoiceSelectedIndex ) {
			convertView.setBackgroundColor(mContext.getResources().getColor(
					R.color.subcategory_background_over_color));
		} else {
			convertView.setBackgroundColor(mContext.getResources().getColor(
					R.color.trasparent_color));
		}
		
		Order invoice = (Order)this.getItem(position);
		if (invoice != null) {
			((TextView) convertView).setText(invoice.getInvoiceTitle());
		}
		
		return convertView;
	}

	public void setInvoiceSelectedIndex(int index) {

		this.mCurrentInvoiceSelectedIndex = index;
		notifyDataSetChanged();
	}

}
